/**
 * 个人试卷
 */
import request from "../utils/request";

export const personPageByUid = ({pageSize=10,currentPage=1,uid}) =>{
    let url = `/api/questions/getAnswerQuestion?pageSize=${pageSize}&currentPage=${currentPage}&uid=${uid}`;
    return request.get(url)
}

/**
 * 试卷类型
 */
interface resultItem {
    name: string;
    id: string;
}


export interface IPageTypes {
    data: {
        result:resultItem[]
    };
    message: string;
    statusCode: number;
}

export const getPageTypes = ():Promise<IPageTypes>=>{
    let url = '/api/questions/types';
    return request.get(url)
}

/**
 * 获取试卷列表
 */
/*试卷列表*/
export interface questionListItem {
    answerCount: number;
    createTime: string;
    isCollection: boolean;
    _id: string;
    title: string;
    userName: string;
    singleCount: number;
    totalCount: number;
    judgementCount: number;
    questionType: string;
    multipleCount: number;
    isAnswer: boolean;
}

export interface IPageList {
    data: {
        total: number;
        questionList: Array<questionListItem>;
    }
    message: string;
    statusCode: number;
}

export const getPageList = (type):Promise<IPageList>=> {
    let url = '/api/questions/getQuestion?questionType=' + type + '&pageSize=100&currentPage=1';
    return request.get(url);
}

/*试卷详情*/
/*Options*/
export class Options {
    A: string;
    B: string;
    C: string;
    D: string;
}


/*SingleQuestion*/
export class SingleQuestion {
    id: string;
    title: string;
    options: Options;
    answer: string;
    message:any
}


/*MultipleQuestion*/
export class MultipleQuestion {
    id: string;
    title: string;
    options: Options;
    answer: any;
    message: any;
}


/*AnswerQuestion*/
export class AnswerQuestion {
    id: string;
    title: string;
    answer: string;
    message: any;
}


/*JudgementQuestion*/
export class JudgementQuestion {
    id: string;
    title: string;
    answer: string;
    message: any;
}

/*QuestionList*/
export class QuestionList {
    title: string;
    singleQuestion: SingleQuestion[];
    multipleQuestion: MultipleQuestion[];
    answerQuestion: AnswerQuestion[];
    judgementQuestion: JudgementQuestion[];
    questionType: string;
}

/*tsModel12*/
export class IQuestion {
    statusCode: number;
    message: string;
    data: {
        questionList: QuestionList;
    };
}

export const getPageById = (id):Promise<IQuestion>=> {
    let url = '/api/questions/getQuestionById/' + id;
    return request.get(url);
}
/**
 * 提交试卷
 */
export const submitExam = (data) =>{
    let url = '/api/questions/submitQuestion';
    return request.post(url,data)
}

/**
 * 答卷详情
 * */

export const  examInfoById = (id)=> {
    let url = '/api/questions/getAnswerQuestionById?id=' + id;
    return request.get(url);
}
